package com.ruoyi.common.utils;

import com.ruoyi.common.exception.CustomException;
import org.apache.commons.lang3.StringUtils;

/**
 * 断言工具类
 *
 * @author yihwang
 * @since 2021/07/02
 **/
public class AssertUtils {

    private AssertUtils() {
    }

    public static void isNull(Object obj, String message) {
        if (obj != null) {
            throw new CustomException(message);
        }
    }

    public static void notNull(Object obj, String message) {
        if (obj == null) {
            throw new CustomException(message);
        }
    }

    public static void isTrue(boolean value, String message) {
        if (!value) {
            throw new CustomException(message);
        }
    }

    public static void isFalse(boolean value, String message) {
        if (value) {
            throw new CustomException(message);
        }
    }

    public static void notEmpty(String str, String message) {
        if (str == null || str.length() == 0) {
            throw new CustomException(message);
        }
    }

    public static void isNotBlank(String str, String message) {
        if (StringUtils.isBlank(str)) {
            throw new CustomException(message);
        }
    }

}
